<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>敏捷开发平台</title>

    <!-- 预加载提示（非阻塞） -->
    <link rel="preload" href="/luckysheet/plugins/css/pluginsCss.css" as="style" onload="this.rel='stylesheet'">
    <link rel="preload" href="/luckysheet/plugins/plugins.css" as="style" onload="this.rel='stylesheet'">
    <link rel="preload" href="/luckysheet/css/luckysheet.css" as="style" onload="this.rel='stylesheet'">
    <link rel="preload" href="/luckysheet/assets/iconfont/iconfont.css" as="style" onload="this.rel='stylesheet'">

    <!-- 异步加载的备用方案 -->
    <noscript>
        <!-- 原生加载方案（支持无JS环境） -->
        <link rel='stylesheet' href='/luckysheet/plugins/css/pluginsCss.css'>
        <link rel='stylesheet' href='/luckysheet/plugins/plugins.css'>
        <link rel='stylesheet' href='/luckysheet/css/luckysheet.css'>
        <link rel='stylesheet' href='/luckysheet/assets/iconfont/iconfont.css'>
    </noscript>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>

<!-- 动态加载脚本 -->
<script>
    // 定义懒加载方法
    function loadLuckysheet() {
        // 如果已经加载则跳过
        if (window.__LUCKY_SHEET_LOADED__) return;

        // 创建加载器
        const loadResources = async () => {
            // 并行加载CSS（已通过preload处理）
            // 顺序加载JS
            await loadScript('/main/luckysheet/plugins/js/plugin.js');
            await loadScript('/main/luckysheet/luckysheet.umd.js');

            window.__LUCKY_SHEET_LOADED__ = true;
            console.log('Luckysheet资源加载完成');
        };

        // 脚本加载方法
        const loadScript = (src) => new Promise((resolve, reject) => {
            const script = document.createElement('script');
            script.src = src;
            script.onload = resolve;
            script.onerror = reject;
            document.body.appendChild(script);
        });

        // 执行加载
        loadResources().catch(err => {
            console.error('资源加载失败:', err);
        });
    }

    if ('requestIdleCallback' in window) {
        window.requestIdleCallback(loadLuckysheet);
    } else {
        setTimeout(loadLuckysheet, 2000);
    }
</script>
</body>
</html>
